﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Yoozoo.Managers.ResourceManagerV2.Runtime;

namespace Yoozoo.Gta.Common
{
    public class FlyItemQuality : MonoBehaviour
    {
        public SpriteRenderer _qualityBg;
        private ResLoader loader;
        public void UpdateQuality(string path)
        {
            if (_qualityBg == null || string.IsNullOrEmpty(path))
            {
                return;
            }
            if (path.Length <= 0)
            {
                _qualityBg.gameObject.SetActive(false);
            }
            else 
            {
                if (loader == null)
                {
                    loader = ResLoader.Alloc();
                }
                loader.Add2Load("Assets/ResourcesAssets/" + path + ".png", typeof(Sprite), (success, assetName, asset) =>
                {
                    if (!success)
                        return;
                    var sprite = asset as Sprite;
                    _qualityBg.sprite = sprite;
                    _qualityBg.gameObject.SetActive(true);
                    Debug.Log("[UpdateQuality] show => " + assetName);
                });
                loader.Load();
            }
        }
        private void OnDestroy()
        {
            if (loader != null)
            {
                loader.Recycle2Cache();
                loader = null;
            }
        }
    }
}
